package com.joysuch.wwyt.bp.entity.investigate;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.joysuch.wwyt.app.bean.AppInvestigateDto;
import com.joysuch.wwyt.bp.bean.BpBaseUserBean;
import com.joysuch.wwyt.bp.bean.investigate.vo.BpPlanNameVO;
import com.joysuch.wwyt.core.support.AutoSetCommonFieldListener;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;

import static javax.persistence.GenerationType.IDENTITY;

/**
 * @Author ZhangDong
 * @Date 2020/3/25 14:15
 */
@EntityListeners({AuditingEntityListener.class, AutoSetCommonFieldListener.class})
@Entity
@Table(name = "wwyt_bp_investigate_plan")
@SQLDelete(sql = "update wwyt_bp_investigate_plan set DELETE_FLAG = '1' where id= ?")
@SQLDeleteAll(sql = "update wwyt_bp_investigate_plan set DELETE_FLAG = '1' where id= ?")
@Where(clause = "DELETE_FLAG = '0'")
@Data
public class BpInvestigatePlan implements Comparable<BpInvestigatePlan> {

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @ApiModelProperty("主键id")
    private Long id;
    @ApiModelProperty("检查计划名称")
    private String checkPlanName;
    @ApiModelProperty("检查类型id")
    private Long typeId;
    @ApiModelProperty("检查类型名称")
    private String typeName;
    @ApiModelProperty("检查方式")
    private String checkWay;
    @ApiModelProperty("排查地点")
    private String checkLocation;
    @ApiModelProperty("备注")
    private String remark;
    @ApiModelProperty("关联排查表id")
    private Long safeTableId;
    @ApiModelProperty("检查项目id集合json串")
    private String checkItem;

    @ApiModelProperty("指定人员id字符串:存入数据库")
    private String executor;
    @ApiModelProperty("异常和提醒人员集合")
    private String remindUserJson;

    @ApiModelProperty("排查频率: 临时性; 周期性")
    private String checkRate;
    @ApiModelProperty("排查频次")
    private String checkRateDescribe;

    @ApiModelProperty("启用/停用")
    private String initiateStatus = "停用";

    @ApiModelProperty("计划排查日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private LocalDate planDate;

    @ApiModelProperty("计划排查日期- 非周期行计划结束时间")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private LocalDate planEndDate;

    @ApiModelProperty("周期单位: 日; 月")
    private String periodUnit;
    @ApiModelProperty("日/月 周期设置,eg: 按天 每1天")
    private Integer periodDays;

    @ApiModelProperty("周期月 开始时间")
    private Integer monthStartDate;
    @ApiModelProperty("日/月 周期设置,eg: 按周 周一")
    private String periodJson;
    @ApiModelProperty("计划开始时间")
    private Date planStartTime;
    @ApiModelProperty("计划结束时间")
    private Date planEndTime;

    @ApiModelProperty("首次任务时间")
    private String firstTaskTime;

    private String checkDepartJson;
    private String checkJobJson;

    @Transient
    @ApiModelProperty("指定人员id集合:返给前端")
    private List<BpBaseUserBean> userList;
    @Transient
    private List<BpInvestigateStoreDetail> storeDetailList;
    @Transient
    @ApiModelProperty("app隐患排查计划下-检查项目集合")
    private List<AppInvestigateDto> storeDetailAppList;
    @Transient
    @ApiModelProperty("上次排查日期")
    private Date latestCheckDate;

    @ApiModelProperty("上次生成任务日期")
    private Date lastProduceDate;

    @ApiModelProperty("检查岗位")
    private Long checkJob;

    @ApiModelProperty("隐患排查内容Id")
    private Long hiddenDangerContentId;

    @ApiModelProperty("所属风险点")
    private Long riskPointId;

    @ApiModelProperty("所属风险点评估")
    private Long pointEvaluationId;

    @ApiModelProperty("数据来源类型")
    private Integer sourceType;

    @ApiModelProperty("是否1:失效,0:未失效")
    private String invalidFlag;
    @ApiModelProperty("失效原因,1:整改未完成，0:未检")
    private String invalidReason;

    @ApiModelProperty("执行单位(0：人员  1：岗位   2：部门)")
    private Integer executiveUnit;
    @ApiModelProperty("排查单位id(部门id或者岗位id)")
    private Long unitId;
    @ApiModelProperty("隐患问题描述")
    private String hiddenDangersDesc;

    @ApiModelProperty(value = "排查类型")
    private Long troubleshootingType;

    //通用字段
    @ApiModelProperty("创建人")
    @org.springframework.data.annotation.CreatedBy
    @JsonIgnore
    private Long createBy;
    @ApiModelProperty("创建时间")
    @org.springframework.data.annotation.CreatedDate
    @JsonIgnore
    private java.time.LocalDateTime createTime;
    @ApiModelProperty("更新人")
    @org.springframework.data.annotation.LastModifiedBy
    @JsonIgnore
    private Long updateBy;
    @ApiModelProperty("更新时间")
    @org.springframework.data.annotation.LastModifiedDate
    @JsonIgnore
    private java.time.LocalDateTime updateTime;
    @ApiModelProperty("租户")
    private Long tenentId;
    @ApiModelProperty("组织机构代码")
    private String orgCode;
    @ApiModelProperty("删除标记")
    @JsonIgnore
    private String deleteFlag;

    @Override
    public int compareTo(BpInvestigatePlan o) {
        return this.id.compareTo(o.id);
    }

    private transient List<BpPlanNameVO> departs;
    private transient List<BpPlanNameVO> jobs;
}
